package thread;

public class MyThread2 {  // 线程等待
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                System.out.println("线程工作中!");

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        System.out.println("线程开始");
        t.start();
        System.out.println("开始等待");
        t.join();
        System.out.println("等待结束");
    }
}
